<script setup>
defineProps({
  previewData: {
    type: Object,
    required: true
  }
});
</script>

<template>
  <div class="card result-preview">
    <h2 class="result-title">
      <i-ep-View class="mr-2" />
      处理结果预览
    </h2>
    <el-tabs type="border-card" class="preview-tabs">
      <el-tab-pane v-for="(rows, sheet) in previewData" :key="sheet" :label="sheet">
        <el-table
          v-if="rows.length"
          :data="rows"
          border
          stripe
          height="400px"
          class="preview-table"
        >
          <el-table-column
            v-for="key in Object.keys(rows[0] || {})"
            :key="key"
            :prop="key"
            :label="key"
            show-overflow-tooltip
            min-width="120"
          />
        </el-table>
        <div v-else class="empty-data"><el-empty description="该表无数据" /></div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<style scoped>
.card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 20px 0 rgba(0, 0, 0, 0.08);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid #ebeef5;
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 6px 24px 0 rgba(0, 0, 0, 0.12);
}

.result-preview {
  margin-top: 30px;
}

.result-title {
  margin-bottom: 20px;
  color: #303133;
  font-size: 22px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-tabs {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.preview-table {
  width: 100%;
}

.preview-table :deep(.el-table__header) {
  font-weight: 600;
}

.empty-data {
  padding: 40px 0;
}
</style>
